package com.zb.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.Category;
import com.zb.entity.Employee;
import com.zb.entity.PageData;
import com.zb.mapper.CategoryMapper;
import com.zb.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Integer addCategorys(Category category) {
        return categoryMapper.insert(category);
    }

    //分页查询菜品分类
    @Override
    public PageData pageSelectCategory(Integer page, Integer pageSize) {
        LambdaQueryWrapper<Category> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        Page<Category> catePage = new Page<>(page, pageSize);
        IPage<Category> empIpage = categoryMapper.selectPage(catePage, lambdaQueryWrapper);
        PageData data = new PageData<Category>();
        data.setPage((int) empIpage.getPages());
        data.setPageSize((int) empIpage.getSize());
        data.setTotal((int) empIpage.getTotal());
        data.setList(empIpage.getRecords());
        return data;
    }

    // 根据id查询菜品分类详情
    @Override
    public Category getCategoryById(Long id) {
        LambdaQueryWrapper<Category> cateQuery = new LambdaQueryWrapper<>();
        cateQuery.eq(Category::getId, id);
        return categoryMapper.selectOne(cateQuery);
    }

    @Override
    public Integer updateCategory(Category category) {
        LambdaQueryWrapper<Category> categoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
        return categoryMapper.updateById(category);
    }
}
